package com.yonyou.pmclouds.basecom.bp.template;

import java.util.ArrayList;
import java.util.List;

import com.yonyou.pmclouds.basecom.bp.processor.GenIdMultiProcessor;
import com.yonyou.pmclouds.basecom.bp.processor.UpdateTsMultiProcessor;
import com.yonyou.pmclouds.basecom.dao.BaseMapper;
import com.yonyou.pmclouds.basecom.entity.Entity;
import com.yonyou.pmclouds.basecom.exception.BusinessException;

/**
 * 多个实体插入模板
 * 
 * @author zhangwce
 */
public  class MultiInsertBpTemplate<T extends Entity> extends MultiOperateBpTemplate<T> {

    private BaseMapper<T> mapper;

    public MultiInsertBpTemplate(BaseMapper<T> mapper) {
        this(mapper, true);
    }

    public MultiInsertBpTemplate(BaseMapper<T> mapper, boolean genId) {
        this.mapper = mapper;
        if (genId) {
            addBeforeProcessor(new GenIdMultiProcessor<T>());
        }
        addBeforeProcessor(new UpdateTsMultiProcessor<T>());
    }

    @Override
    protected void operateDirect(T[] vos, T[] origs) {
    	
    	List<T> list = new ArrayList<T>();
    	for (T t : vos) {
    		list.add(t);
		}
    	
        mapper.batchInsert(list);
    }

    public T[] insert(T[] vos) throws BusinessException {
        return execute(vos);
    }

	
}
